﻿using NFine.Data;
using NFine.Domain.Entity.SystemManage;
using NFine.Domain.IRepository.SystemManage;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq;
namespace NFine.Repository.SystemManage
{
    public class AreaRepository : RepositoryBase<AreaEntity>, IAreaRepository
    {
        public List<AreaEntity> GetAgList(Expression predicate)
        {
            using (var db = new RepositoryBase())
            {
                var baselinq = (from sh in db.DbSet<AreaEntity>()
                                join u1 in db.DbSet<UserEntity>() on sh.F_Id equals u1.ProxyCode
                                select new { sh, u1 })
                                .OrderBy(p => p.sh.F_Id);


                List<AreaEntity> lst = new List<AreaEntity>();
                foreach (var obj in baselinq)
                {
                    obj.sh.F_Id = obj.sh.F_Id;
                    obj.sh.F_ParentId = obj.sh.F_ParentId;
                    obj.sh.F_FullName = obj.sh.F_FullName;
                    obj.sh.F_EnCode = obj.sh.F_EnCode;
                    obj.sh.UserCode = obj.u1.F_Account;
                    obj.sh.UserName = obj.u1.F_RealName;
                    obj.sh.UserCreatorTime = obj.u1.F_CreatorTime;
                    lst.Add(obj.sh);
                }
                return lst;
            }
        }
    }
}
